﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EvincePayroll.Data;
using EvincePayroll.Utility;

namespace EvincePayroll.Logic
{
   public class PageTemplateLogic:BaseLogic
    {
        public PageTemplateLogic(string emailId)
            : base(emailId)
        { }

       //Completed
        public PageTemplateData GetPageTemplate(string pageId)
        {
            try
            {
               return db.GetPageTemplateDataById(pageId);
                //return db.GetPageTemplate(pageId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

       //Completed
        public bool AddPage(PageTemplateData page,string email,string PageID)
        {
            bool result = false;
            try
            {
                if (string.IsNullOrEmpty(PageID))
                {
                    result = db.InsertPageTemplate(page);
                }
                if (!string.IsNullOrEmpty(PageID))
                {
                    var pageTemplate = db.GetPageTemplateDataById(PageID);

                    #region Page template update data
                    pageTemplate.PageCode = page.PageCode;
                    pageTemplate.DisplayTitle = page.DisplayTitle;
                    pageTemplate.MetaKeywords = page.MetaKeywords;
                    pageTemplate.MetaDescription = page.MetaDescription;
                    pageTemplate.Contents = page.Contents;
                    pageTemplate.Status = page.Status; 
                    #endregion
                    result = db.UpdatePageTemplate(pageTemplate);
                }
                //return db.AddPage(page, email, PageID);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
            return result;
        }
       //Completed
        public List<PageTemplateData> GetPageTemplateList()
        {
            try
            {
       //         return db.GetPageTemplateDataList();
                return db.GetPageTemplateDataList().Where(x=>x.Status.Equals(1)).ToList();
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
       //Completed
        public List<PageTemplateData> GetAllPageList()
        {
            try
            {
                return db.GetPageTemplateDataList();
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

       //Completed
        public bool DeleteCMS(string pageId)
        {
            try
            {
                return db.DeletePageTemplate(pageId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }
    }

}
